﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using DataTransferObject;
namespace _5ChickDeal.Ajax
{
    public partial class GetDealsImages : System.Web.UI.Page
    {
        DataClassesDataContext db;
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["admin"] == null)
            //{
            //    return;
            //}
            db = new DataClassesDataContext();
            if (Request.QueryString["xoa"] != null)
            {
                try
                {

                    String name = Request.QueryString["xoa"];
                    HinhAnh ha = db.HinhAnhs.First(h => h.ten == name);

                    //Xóa hình trong thư mục
                    File.Delete(Server.MapPath("~/Resource/ImageDeals/") + name);

                    //Xóa hình trong databasle'
                    db.HinhAnhs.DeleteOnSubmit(ha);
                    db.SubmitChanges();


                }
                catch { }
            }
            try
            {
                int? id = null;
                if (Request.QueryString["deal"] != null)
                {
                    id = int.Parse(Request.QueryString["deal"]);
                }
                
                var source = from h in db.HinhAnhs
                             where h.madeal == id||h.madeal==null
                             select h;
                DataList1.DataSource = source;
                DataList1.DataBind();
            }
            catch { }
        }
    }
}

